package com.sangmo.fts.process.storage.model;

import com.sangmo.boot.framework.data.entity.general.SoftDeleteEntity;
import com.sangmo.boot.framework.data.json.meta.ExtView;
import com.sangmo.boot.framework.data.json.meta.One;
import com.sangmo.boot.framework.plugin.dataview.def.meta.DataField;
import com.sangmo.boot.framework.plugin.dataview.def.meta.DataView;
import com.sangmo.fts.basic.model.Company;
import com.sangmo.fts.common.IConstants;
import org.hibernate.annotations.SQLDelete;
import org.hibernate.annotations.SQLDeleteAll;
import org.hibernate.annotations.Where;

import javax.persistence.Entity;
import javax.persistence.Table;
import java.util.Date;

@Entity
@Table(name = "csf_lading_bill")
@DataView
@ExtView
@SQLDelete(
        sql = "UPDATE #{entityName} SET deleted = CURRENT_TIMESTAMP WHERE id = ?"
)
@SQLDeleteAll(
        sql = "UPDATE #{entityName} SET deleted = CURRENT_TIMESTAMP WHERE id = ?"
)
@Where(
        clause = "deleted = 0"
)
public class CsfLadingBill extends SoftDeleteEntity {

    @DataField(value = IConstants.DATA_TYPE.LONG, required = true, index = true)
    private Long trainingId;

    @DataField(value = IConstants.DATA_TYPE.STRING_50,required = true, unique = true)
    private String code;

    private String billCode;

    @One(value = "loan", target = CsfLoan.class, groups = {"CsfLadingBill.search","CsfLadingBill.detail"})
    @DataField(value = IConstants.DATA_TYPE.LONG, required = true, index = true)
    private Long loanId;

    @DataField(value = IConstants.DATA_TYPE.LONG, required = true)
    private Long agreementId;

    @One(value = "applyCompany", target = Company.class, fieldset = {"id","name"})
    @DataField(value = IConstants.DATA_TYPE.LONG, required = true, index = true)
    private Long applyId;

    @One(value = "bank", target = Company.class, fieldset = {"id","name"})
    @DataField(value = IConstants.DATA_TYPE.LONG, required = true, index = true)
    private Long bankId;

    @One(value = "regulatorCompany", target = Company.class, fieldset = {"id","name"})
    @DataField(value = IConstants.DATA_TYPE.LONG, required = true, index = true)
    private Long regulatorId;

    @DataField(value = IConstants.CSF_LADING_BILL_DATA_TYPE.BILL_STATE, required = true, index = true)
    private String state = States.PENDING;

    @DataField(value = IConstants.CSF_LADING_BILL_DATA_TYPE.BANK_ACK_STATE, required = true, index = true)
    private String bankAckState = BankAckStates.PENDING;

    @DataField(value = IConstants.CSF_LADING_BILL_DATA_TYPE.STORAGE_ACK_STATE, required = true, index = true)
    private String storageAckState = StorageAckStates.PENDING;

    private Long billApplyDoc;

    private Long billConfirmDoc;

    private Long billReceiptDoc;

    private Date pickDate;

    public Long getTrainingId() {
        return trainingId;
    }

    public void setTrainingId(Long trainingId) {
        this.trainingId = trainingId;
    }

    public String getCode() {
        return code;
    }

    public void setCode(String code) {
        this.code = code;
    }

    public String getBillCode() {
        return billCode;
    }

    public void setBillCode(String billCode) {
        this.billCode = billCode;
    }

    public Long getLoanId() {
        return loanId;
    }

    public void setLoanId(Long loanId) {
        this.loanId = loanId;
    }

    public Long getAgreementId() {
        return agreementId;
    }

    public void setAgreementId(Long agreementId) {
        this.agreementId = agreementId;
    }

    public Long getApplyId() {
        return applyId;
    }

    public void setApplyId(Long applyId) {
        this.applyId = applyId;
    }

    public Long getBankId() {
        return bankId;
    }

    public void setBankId(Long bankId) {
        this.bankId = bankId;
    }

    public Long getRegulatorId() {
        return regulatorId;
    }

    public void setRegulatorId(Long regulatorId) {
        this.regulatorId = regulatorId;
    }

    public String getState() {
        return state;
    }

    public void setState(String state) {
        this.state = state;
    }

    public String getBankAckState() {
        return bankAckState;
    }

    public void setBankAckState(String bankAckState) {
        this.bankAckState = bankAckState;
    }

    public String getStorageAckState() {
        return storageAckState;
    }

    public void setStorageAckState(String storageAckState) {
        this.storageAckState = storageAckState;
    }

    public Long getBillApplyDoc() {
        return billApplyDoc;
    }

    public void setBillApplyDoc(Long billApplyDoc) {
        this.billApplyDoc = billApplyDoc;
    }

    public Long getBillConfirmDoc() {
        return billConfirmDoc;
    }

    public void setBillConfirmDoc(Long billConfirmDoc) {
        this.billConfirmDoc = billConfirmDoc;
    }

    public Long getBillReceiptDoc() {
        return billReceiptDoc;
    }

    public void setBillReceiptDoc(Long billReceiptDoc) {
        this.billReceiptDoc = billReceiptDoc;
    }

    public Date getPickDate() {
        return pickDate;
    }

    public void setPickDate(Date pickDate) {
        this.pickDate = pickDate;
    }

    public interface States {
        String PENDING = "PENDING";
        String SUBMITTED = "SUBMITTED";
    }

    public interface BankAckStates {
        String PENDING = "PENDING"; //待确认
        String CONFIRMED = "CONFIRMED"; //已确认
    }

    public interface StorageAckStates {
        String PENDING = "PENDING"; //待确认
        String COMPLETED = "COMPLETED"; //完成
    }
}
